package com.boxuegu.boxueguapiservice.controller;


import com.boxuegu.boxueguapiservice.entity.UserCourse;
import com.boxuegu.boxueguapiservice.entity.Video;
import com.boxuegu.boxueguapiservice.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Vincent
 */
@RestController
@RequestMapping("/video")
public class VideoController {
  @Autowired
  private VideoService videoService;
  
  /**
   * 查询观看记录
   *
   * @param param userId 用户id
   * @return 返回观看记录
   */
  @PostMapping("/findHistoryByUserId")
  @ResponseBody
  public Map<String, Object> findHistoryByUserId(@RequestBody Map<String, Object> param) {
    Map<String, Object> map = new HashMap<>();
    int userId = (int) param.get("userId");
    List<UserCourse> videoList = videoService.findHistoryByUserId(userId);
    if (videoList != null) {
      map.put("msg", "成功");
      map.put("success", true);
      map.put("list", videoList);
    } else {
      map.put("msg", "失败");
      map.put("success", false);
    }
    return map;
  }
  
  /**
   * 查询视频详情信息
   * @param param  视频ID
   * @return 视频详情
   */
  @PostMapping("/findVideoById")
  @ResponseBody
  public Map<String, Object> findVideoById(@RequestBody Map<String, Object> param) {
    Map<String, Object> map = new HashMap<>();
    int id = (int) param.get("id");
    Video video = videoService.findVideoById(id);
    if (video != null) {
      map.put("msg", "成功");
      map.put("success", true);
      map.put("video", video);
    } else {
      map.put("msg", "失败");
      map.put("success", false);
    }
    return map;
  }
}
